package definition;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.annotation.AnnotatedBeanDefinitionReader;

/**
 * 基于注解的 BeanDefinitionReader
 * @author jackcfan
 * @date 2021/9/25
 */
public class AnnotatedBeanDefinitionReaderTest {

    public static void main(String[] args) {
        DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
        AnnotatedBeanDefinitionReader beanDefinitionReader = new AnnotatedBeanDefinitionReader(beanFactory);

        // 注册当前类 (非 @Component 注解标注)
        // 普通类作为 Component 注册到 Spring IoC 容器
        beanDefinitionReader.register(AnnotatedBeanDefinitionReaderTest.class);

        /**
         * 依赖查找
         * Bean 名称来自 {@link org.springframework.context.annotation.AnnotationBeanNameGenerator}
         * */
        AnnotatedBeanDefinitionReaderTest bean = beanFactory.getBean("annotatedBeanDefinitionReaderTest", AnnotatedBeanDefinitionReaderTest.class);
        System.out.println("bean:"+bean);
    }
}
